home *** CD-ROM | disk | FTP | other *** search
- //____________________________________________________________
- // QDGXShape.c
- //
- // Copyright © Dan Parks Sydow, 1995
- // From the book:
- // "Graphics and Sound Programming Techniques for the Mac",
- // M&T Books, 1995
-
-
- //____________________________________________________________
-
- #include "PrintingManager.h" // defines the Gestalt selector code gestaltGXPrintingMgrVersion
- #include "graphics macintosh.h" // defines the Gestalt selector code gestaltGraphicsVersion
- #include "graphics toolbox.h" // prototype for the GX function GXNewWindowViewPort()
- #include "graphics libraries.h" // prototypes for several GX functions
-
-
- //____________________________________________________________
-
- Boolean IsQuickDrawGXAvailable( void );
- void InitializeToolbox( void );
- void InitializeQuickDrawGX( void );
- void OpenDisplayWindow( void );
- void CleanUpQuickDrawGXandQuit( void );
- void CreateGXLineShape( void );
-
-
- //____________________________________________________________
-
- #define kGXClientHeapSizeBytes 150 * 1024
-
-
- //____________________________________________________________
-
- gxGraphicsClient gGXClient;
- Boolean gQuickDrawGXPresent;
- WindowPtr gDisplayWindow = nil;
- gxViewPort gWindowViewPort;
- Boolean gDone = false;
- gxShape gLineShape;
-
-
- //____________________________________________________________
-
- void main( void )
- {
- InitializeToolbox();
-
- gQuickDrawGXPresent = IsQuickDrawGXAvailable();
- if ( gQuickDrawGXPresent == true )
- InitializeQuickDrawGX();
- else
- ExitToShell();
-
- OpenDisplayWindow();
-
- while ( gDone == false )
- {
- if ( Button() )
- CleanUpQuickDrawGXandQuit();
- }
- }
-
-
- //____________________________________________________________
-
- Boolean IsQuickDrawGXAvailable( void )
- {
- OSErr theError;
- long theResult;
-
- theError = Gestalt( gestaltGraphicsVersion, &theResult );
- if ( theError != noErr )
- return ( false );
-
- theError = Gestalt( gestaltGXPrintingMgrVersion, &theResult );
- if ( theError != noErr )
- return ( false );
-
- return ( true );
- }
-
-
- //____________________________________________________________
-
- void InitializeQuickDrawGX( void )
- {
- gxGraphicsError theGXgraphicsError;
- OSErr theGXprintError;
-
- gGXClient = GXNewGraphicsClient( nil, kGXClientHeapSizeBytes, 0L );
-
- GXEnterGraphics();
- theGXgraphicsError = GXGetGraphicsError( nil );
- if ( theGXgraphicsError == out_of_memory )
- ExitToShell();
-
- theGXprintError = GXInitPrinting();
- if ( theGXprintError != noErr )
- ExitToShell();
- }
-
-
- //____________________________________________________________
-
- void OpenDisplayWindow( void )
- {
- gDisplayWindow = GetNewCWindow( 128, nil, (WindowPtr)-1L );
- ShowWindow( gDisplayWindow );
- SetPort( gDisplayWindow );
-
- gWindowViewPort = GXNewWindowViewPort( gDisplayWindow );
-
- CreateGXLineShape();
-
- GXSetShapeViewPorts( gLineShape, 1, &gWindowViewPort );
-
- GXDrawShape( gLineShape );
- }
-
-
- //____________________________________________________________
-
- void CreateGXLineShape( void )
- {
- gxLine theLineGeometry = { {ff(50), ff(100)}, {ff(300), ff(60)} };
-
- gLineShape = GXNewShape( gxLineType );
- GXSetLine( gLineShape, &theLineGeometry );
- }
-
-
- //____________________________________________________________
-
- void CleanUpQuickDrawGXandQuit( void )
- {
- OSErr theGXprintError;
-
- if ( gDisplayWindow != nil )
- {
- GXDisposeViewPort( gWindowViewPort );
- DisposeWindow( gDisplayWindow );
- }
-
- theGXprintError = GXExitPrinting();
-
- GXExitGraphics();
-
- GXDisposeGraphicsClient( gGXClient );
-
- gDone = true;
- }
-
-
- //____________________________________________________________
-
- void InitializeToolbox( void )
- {
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( 0L );
- FlushEvents( everyEvent, 0 );
- InitCursor();
- }
-